package MLP {
	import UIFree.uif_loader;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class mlp_effectLayer extends Sprite {
		private var _size		: Point;
		private var _params		: Object;
		private var _bitmap		: Bitmap;
		
		public static var URLPATH: String = '';
		
		public function mlp_effectLayer(a_params: Object) {
			super();
			_size 	= new Point();
			_params = a_params;
			_bitmap = new Bitmap();
		}
		
		public function get params(): Object {
			return _params;
		}
		
		override public function get width():Number {
			return _size.x;
		}
		
		override public function get height():Number {
			return _size.y;
		}

		override public function set width(a_width: Number): void {
			_size.x = a_width;
		}
		
		override public function set height(a_height: Number): void {
			_size.y = a_height;
		}
		
		public function get card_photo(): Bitmap {
			return null;
		}
		
		public function get bitmap(): Bitmap {
			return _bitmap; 
		}
		
		public function get contentSize(): Point {
			return new Point(width, height);
		}
		
		public function get maskInfo(): Object {
			return {};
		}
		
		public function drawBitmapData(a_element: DisplayObject): void {
			if (bitmap.bitmapData) bitmap.bitmapData.dispose();
			bitmap.bitmapData = new BitmapData(a_element.width, a_element.height, true, 0);
			bitmap.bitmapData.draw(a_element);
		}
		
		public function dispose(): void {
			if (_bitmap.bitmapData) _bitmap.bitmapData.dispose();
			remove();
		}
		
		public function remove(): void {
			if (parent) parent.removeChild(this);
		}
		
		public function get fileName(): String {
			return params.file?params.file:('f' + params.id + '.swf');
		}
		
		public function get This(): mlp_effectLayer {
			return this;
		}
		
		public function load(doComplete: Function=null): void {
			var loader: uif_loader = new uif_loader(null, URLPATH + fileName, function(e: Event): void {
				var PJFilter: Class = (e.target as LoaderInfo).applicationDomain.getDefinition(params.className?params.className:'PJFilter');
				var _effect	: Object = new PJFilter();
				var scale	: Number = 1;
				_effect.parameters = {
					parent		: This, 
					bounds		: new Rectangle(0, 0, width / scale, height / scale), 
					info		: params
				};
				if (doComplete != null) doComplete(_effect);
				loader.unload();
			});
		}
	}
}